package com.kjlink.widget.oa;

import cn.hutool.crypto.digest.DigestUtil;
import cn.xuqiudong.common.base.craw.BaseCrawl;
import org.apache.commons.codec.digest.DigestUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 描述:
 *  KJOA-148
 * @author Vic.xu
 * @since 2025-08-19 16:52
 */
public class OaApi extends BaseCrawl {

    public static OaApi INSTANCE = new OaApi();

    /**
     * 获取所有员工信息
     */
    public static final String URL = "http://192.168.80.58:8087/KjlinkPmsBackend/oa/sync/user";

    @Override
    protected int getTimeout() {
        return 20000;
    }

    public static void main2(String[] args) throws IOException {
        String sign = "a02c3647351d4d158fb4e79384050cbe";
        String s = signStr(1719541671918L);
        System.out.println(s.equals(sign) ? "sign ok" : "sign error");
        allUser();
    }

    public static void allUser() throws IOException {
        long timestamp = System.currentTimeMillis();
        String bodyText = INSTANCE.con(URL)
                .header("Access-Control-Request-Headers", "oa")
                .header("appId", "newoa")
                .header("Origin", "oa")
                .data("signStr", signStr(timestamp))
                .data("timestamp", timestamp + "")

                .getBodyText();
        System.out.println(bodyText);
    }

    public static String signStr(long timestamp) {
        String str = "newoa" + "gdG9rZW4iLCJhdWQiOiJBUFAiLCJuYmYiOjE3" + timestamp;
        String md5 = DigestUtils.md5Hex(str);
        return md5;
    }

    public static void main(String[] args) {
        String str = "123";
        String s = DigestUtil.md5Hex(str);
        String md5 = DigestUtils.md5Hex(str);
        System.out.println(s.equals(md5));
    }


}
